//
//  UnLoadSureVC.m
//  NtoccShipper
//
//  Created by mac on 2019/12/2.
//  Copyright © 2019 zhuchongjin. All rights reserved.
//

#import "UnLoadSureVC.h"
#import "HDPicModle.h"
#import "GetPhoto.h"
#import "XLImageViewer.h"
#import "OrderListDetailModel.h"
#import "AddOtherFeeVC.h"
#import "GetPhoto.h"

@interface UnLoadSureVC ()<UITableViewDelegate,UITableViewDataSource ,UITextFieldDelegate>{

    FlexFrameView *header;
    UIView* _imgParent;
    int indexReturn;  // 记录图片的位置
    int  indexReplace; //替换的位置
    
    UIView* _imgAbnormalParent;
    int indexAbnormal;  // 记录图片的位置
    int  indexAbnormalReplace; //替换的位置
    
    UIView* _imgLoadImgParent; //
    UIView* _imgUnloadImgParent; //

}
@property (nonatomic,strong) FlexTouchView *touchViewReturn;
@property (nonatomic,strong) FlexTouchView *touchViewAbnormal;
@property (nonatomic,strong) CJTableView *tableView;
@property (nonatomic,strong) UISwitch *switchInRecive; // 是否货单已收 abnormal
@property (nonatomic,strong) UISwitch *switchabnormal; // 是否异常 abnormal
@property (nonatomic,strong) CJLabel *labAbnormalImgIndex;
@property (nonatomic,strong) CJLabel *labReturnOrderImgIndex;
@property (nonatomic,strong) NSMutableArray *arrReturnOrder;
@property (nonatomic,strong) NSMutableArray *arrAbnormalOrder;
@property (nonatomic,assign) BOOL isChangeReturnOrderImg; // 是否更改
@property (nonatomic,assign) BOOL isChangeAbnormalImg; //
@property (nonatomic,strong) OrderListDetailModel *model;
// 其他费用
@property (nonatomic,strong) CJTextField *fieldOtherFee;
/// 装货图片部分
@property (nonatomic,strong) NSMutableArray *arrLoadimgs;
/// 卸货图片部分
@property (nonatomic,strong) NSMutableArray *arrUnloadimgs;
//
@property (nonatomic,strong) CJLabel *labDriverName;
@property (nonatomic,strong) CJLabel *labDriverPhoe;
@property (nonatomic,strong) CJLabel *labCarNum;
@property (nonatomic,strong) CJLabel *labUnloadWeight;
@property (nonatomic,strong) CJLabel *labUnloadTime;
@property (nonatomic,strong) CJLabel *labCoalUnit; // 卸货数量

@property (nonatomic,copy) NSString *strIsReceiptReturn; //回单是否已收：0->未收取，1->已收取
@property (nonatomic,strong) CJTextField *fieldReceiptNum;
@property (nonatomic,copy) NSString *strIsAbnormal;
@property (nonatomic,strong) CJTextField *fieldAbnormalRemark;
@property (nonatomic,strong) CJTextField *fieldAbnormalFee;

@property (nonatomic,strong) CJView *viewShowLoadImg;
@property (nonatomic,strong) CJView *viewShowUnloadImg;
@property (nonatomic,copy) NSString *strOrderExtraFeeList;
@property (nonatomic,strong) NSMutableArray *arrOtherList;
//@property (nonatomic,copy) NSString *strOtherFee;

@end

//  回单的 tag  100  1000   异常的 tag  200 2000
//  装货图片  tag 3000
// 卸货图片 4000
@implementation UnLoadSureVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setTitleName:CJLString(@"卸货确认")];
    [self setBackLeftButton:@""];
    
    self.arrLoadimgs = [[NSMutableArray alloc]init];
    self.arrUnloadimgs = [[NSMutableArray alloc]init];
    self.arrOtherList = [[NSMutableArray alloc]init];
    [self.view addSubview:self.tableView];

    self.arrReturnOrder = [[NSMutableArray alloc]init];
    self.arrAbnormalOrder = [[NSMutableArray alloc]init];
    indexAbnormal= 200;
    indexReturn = 100;
    self.strOrderExtraFeeList = @"";
    self.fieldOtherFee.text = @"";
    [self loadData];
}

//- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
//
//    if (textField == self.fieldOtherFee) {
//
//    }else{
//        return YES;
//    }
//
//}

#pragma mark------------UITextFieldDelegate---------------
//限制只能输入金额的正则表达式
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    if (textField == self.fieldOtherFee) {

        NSString * str = [NSString stringWithFormat:@"%@%@",textField.text,string];
        //匹配以0开头的数字
        DLog(@"======== %@",str);
        NSPredicate * predicate0 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",@"^[0][0-9]+$"];
        //匹配两位小数、整数
        NSPredicate * predicate1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",@"^(([1-9]{1}[0-9]*|[0])\\.?[0-9]{0,2})$"];
        return ![predicate0 evaluateWithObject:str] && [predicate1 evaluateWithObject:str] ? YES : NO;
    }else{
        return YES;
    }
}

- (void)loadData{
    WS(ws);
    self.strIsReceiptReturn = @"0";
    self.strIsAbnormal = @"0";
    [CJNetWork getSourcesOrderListDetailDataWithCode:self.strCode Success:^(id  _Nullable responseObject) {
        
        DLog(@"====== %@",responseObject);
        ws.model = (OrderListDetailModel *)responseObject;
        [ws createTableView];
    }];
}

//上传回单
-(void)onAddImage{
//    DLog(@"++++++++++%d",index);

    if (indexReturn - 100 >= 9) {
        [CJAlert showStringDismissWithDelay:@"最多上传9张图片"];
        return;
    }
    WS(ws);
    [GetPhoto getPhoto:self completion:^(UIImage *curImage, NSData *imageData) {
        [ws upLoadReturnImageUImage:curImage withNSData:imageData];
    }];

}
-(void)removeReturnCell:(UIGestureRecognizer*)sender{
    UIView* cell = sender.view;
    [[XLImageViewer shareInstanse] showNetImages:self.arrReturnOrder index:(int)cell.tag - 100 fromImageContainer:cell];
}

-(void)relpaceReturnCell:(UIGestureRecognizer*)sender{
    
    UIView* cell = [self.view viewWithTag:sender.view.tag - 1000];
      indexReplace = (int)cell.tag - 100;

        self.isChangeReturnOrderImg = YES;
        [GetPhoto getPhoto:self completion:^(UIImage *curImage, NSData *imageData) {
            cell.layer.contents = (id) curImage.CGImage;
            [self upLoadReturnImageUImage:curImage withNSData:imageData];
        }];
//        DLog(@"++++++ %ld",(long)cell.tag);
}


- (void)upLoadReturnImageUImage:(UIImage *)img withNSData:(NSData *)imageData{

    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tps-api/fileUpload",CJBaseUrl);
    NSURL *str = [[NSURL alloc]initFileURLWithPath:[CJControl getImgFilePath:img]];
    NSDictionary *dic = @{
                          @"file":str
                          };
    HDPicModle *model = [[HDPicModle alloc]init];
    model.pic = img;
    model.picData = imageData;
    model.picName = @"file";
    model.fileName = [CJControl getImgFilePath:img];

    WS(ws);
    [[HDNetworking sharedHDNetworking] POST:strURL parameters:dic andPic:model progress:^(NSProgress * _Nullable progress) {
        DLog(@"%lf", 1.0 * progress.completedUnitCount / progress.totalUnitCount);
    } success:^(id  _Nonnull responseObject) {

        NSString *strStatus = CJStringWithFormat(@"%@",responseObject[@"status"]);
        if (strStatus.integerValue == 0) {

            if (ws.isChangeReturnOrderImg) {
                [ws.arrReturnOrder replaceObjectAtIndex:indexReplace withObject:responseObject[@"data"]];
            }else{

                [ws.arrReturnOrder addObject:responseObject[@"data"]];
                UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeReturnCell:)];

                UIView* cell = [[UIView alloc]init];
                cell.tag = indexReturn;
                [cell enableFlexLayout:YES];
                [cell addGestureRecognizer:tap];

                [cell setLayoutAttrStrings:@[
                                            @"width",@"75",
                                            @"height",@"75",
                                            @"margin",@"1%",
                                            @"alignItems",@"center",
                                            @"justifyContent",@"center",
                                            ]];
                [cell setViewAttr:@"bgColor" Value:@"#E4E9ED"];
                [cell setViewAttr:@"borderRadius" Value:@"10"];

                CJView *viewDelete = CJView.viewInit
                .viewFrame(CGRectMake(65, -2, 20, 20))
                .viewbgColor([UIColor cjClearColor])
                ;
                viewDelete.layer.contents = (id) [UIImage imageNamed:@"zcj_delete_img"].CGImage;
                [cell addSubview:viewDelete];

                UITapGestureRecognizer *tapRelpace=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(relpaceReturnCell:)];
                viewDelete.tag = indexReturn + 1000;
                [viewDelete addGestureRecognizer:tapRelpace];
                [_imgParent insertSubview:cell atIndex:indexReturn -100];
                [_imgParent markDirty];
                
                [header layoutIfNeeded];
                self.tableView.tableHeaderView = header;

                cell.layer.contents = (id) img.CGImage;
                self.isChangeReturnOrderImg = NO;
                indexReturn++;
                self.labReturnOrderImgIndex.text = CJStringWithFormat(@"%d/9",indexReturn - 100 + 1);
                if (indexReturn - 100 + 1 > 9) {
                    self.touchViewReturn.hidden = YES;
                }
            }
        }
//        DLog("====== =%@",ws.arrReturnOrder);

    } failure:^(NSError * _Nonnull error) {
        DLog(@"+++++++%@",error);

    }];
}

//上传异常图片
-(void)onAddAbnormalImage{
//    DLog(@"++++++++++%d",index);
    if (indexAbnormal - 200 >= 9) {
        [CJAlert showStringDismissWithDelay:@"最多上传9张图片"];
        return;
    }
    WS(ws);
    [GetPhoto getPhoto:self completion:^(UIImage *curImage, NSData *imageData) {
        [ws upLoadAbnormalImageUImage:curImage withNSData:imageData];
    }];
}

-(void)removeCell:(UIGestureRecognizer*)sender{
    UIView* cell = sender.view;
    [[XLImageViewer shareInstanse] showNetImages:self.arrAbnormalOrder index:(int)cell.tag - 200 fromImageContainer:cell];
}

-(void)relpaceCell:(UIGestureRecognizer*)sender{
    
    UIView* cell = [self.view viewWithTag:sender.view.tag - 2000];
      indexAbnormalReplace = (int)cell.tag - 200;

        self.isChangeAbnormalImg = YES;
        [GetPhoto getPhoto:self completion:^(UIImage *curImage, NSData *imageData) {
            cell.layer.contents = (id) curImage.CGImage;
            [self upLoadAbnormalImageUImage:curImage withNSData:imageData];

        }];
//        DLog(@"++++++ %ld",(long)cell.tag);
}

- (void)upLoadAbnormalImageUImage:(UIImage *)img withNSData:(NSData *)imageData{

    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tps-api/fileUpload",CJBaseUrl);
    NSURL *str = [[NSURL alloc]initFileURLWithPath:[CJControl getImgFilePath:img]];
    NSDictionary *dic = @{
                          @"file":str
                          };
    HDPicModle *model = [[HDPicModle alloc]init];
    model.pic = img;
    model.picData = imageData;
    model.picName = @"file";
    model.fileName = [CJControl getImgFilePath:img];

    WS(ws);
    [[HDNetworking sharedHDNetworking] POST:strURL parameters:dic andPic:model progress:^(NSProgress * _Nullable progress) {
        DLog(@"%lf", 1.0 * progress.completedUnitCount / progress.totalUnitCount);
    } success:^(id  _Nonnull responseObject) {
//        DLog(@"+++++++%@",responseObject);

        NSString *strStatus = CJStringWithFormat(@"%@",responseObject[@"status"]);

        if (strStatus.integerValue == 0) {
            if (ws.isChangeAbnormalImg) {
                [ws.arrAbnormalOrder replaceObjectAtIndex:indexAbnormalReplace withObject:responseObject[@"data"]];
            }else{

                [ws.arrAbnormalOrder addObject:responseObject[@"data"]];
                UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeCell:)];

                UIView* cell = [[UIView alloc]init];
                cell.tag = indexAbnormal;
                [cell enableFlexLayout:YES];
                [cell addGestureRecognizer:tap];

                [cell setLayoutAttrStrings:@[
                                    @"width",@"75",
                                    @"height",@"75",
                                    @"margin",@"1%",
                                    @"alignItems",@"center",
                                    @"justifyContent",@"center",
                                    ]];
                [cell setViewAttr:@"bgColor" Value:@"#E4E9ED"];
                [cell setViewAttr:@"borderRadius" Value:@"10"];

                CJView *viewDelete = CJView.viewInit
                .viewFrame(CGRectMake(65, -2, 20, 20))
                .viewbgColor([UIColor cjClearColor])
                ;
                viewDelete.layer.contents = (id) [UIImage imageNamed:@"zcj_delete_img"].CGImage;
                [cell addSubview:viewDelete];

                UITapGestureRecognizer *tapRelpace=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(relpaceCell:)];
                viewDelete.tag = indexAbnormal + 2000;
                [viewDelete addGestureRecognizer:tapRelpace];

                [_imgAbnormalParent insertSubview:cell atIndex:indexAbnormal -200];

                [_imgAbnormalParent markDirty];
                [header layoutIfNeeded];
                self.tableView.tableHeaderView = header;

                cell.layer.contents = (id) img.CGImage;
                self.isChangeAbnormalImg = NO;
                indexAbnormal++;
                self.labAbnormalImgIndex.text = CJStringWithFormat(@"%d/9",indexAbnormal - 200 + 1);
                if (indexAbnormal - 200 + 1 > 9) {
                    self.touchViewAbnormal.hidden = YES;
                }
            }
        }

//        DLog("====== =%@",ws.arrAbnormalOrder);

    } failure:^(NSError * _Nonnull error) {
        DLog(@"+++++++%@",error);

    }];
}

- (void)btnTurnDownUnloadGoodsAction{
    
    WS(ws);
    CJAlertView *alert = [[CJAlertView alloc]initWithTitle:@"友情提示" strContent:[CJPromptInfo getHintPromptType:@"驳回" withNextStep:@"卸车信息"] ClickOnSure:^(NSString * _Nonnull strSure) {
        [ws btnTurnDownUnloadGoodsInfoAction];
    } ClickOnCancle:^(NSString * _Nonnull strCancle) {
        
    }];
    alert.center=self.view.center;
    WLAlertView * alertView = [[WLAlertView alloc]init];
    alertView.containerView = alert;
    alertView.isTouchOtherUndissmiss = YES;
    [alertView show];
}

- (void)btnTurnDownUnloadGoodsInfoAction{
    
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderDetail/orderDetailFinish",CJBaseUrl);
    NSDictionary *dicPar = @{@"code":self.strCode, //@"16f113c77b7a42a5a9b7d231fc9ad39e", //
                             @"isUnloadingConfirm":@"2",
    };
    
    WS(ws);
    [[HDNetworking sharedHDNetworking] PUT:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
        
        DLog(@"++++++++%@",responseObject);
        if (ws.blockSuccess) {
            ws.blockSuccess(@"");
        }
        [ws pop];
        
    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        
    }];
    
}

/// 创建tableview 等
- (void)createTableView{
    
    //    WS(ws);
    CGRect rcFrame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 0);
    header = [[FlexFrameView alloc] initWithFlex:@"UnLoadSureHeaderView" Frame:rcFrame Owner:self];
    header.flexibleHeight = YES;
    self.fieldAbnormalFee.delegate = self;
    OrderDetailModel *detailModel = self.model.orderDetail;
    OrderModel *orderModel = self.model.order;
    self.labDriverName.text = detailModel.driverName;
    self.labDriverPhoe.text = detailModel.driverPhone;
    self.labCarNum.text = detailModel.vehicleLicense;
    self.labUnloadWeight.text = @(detailModel.unloadQuantity).cj_description;
// isTrunkName  // 单位
    self.labUnloadTime.text = detailModel.signTime;
    if ([CJRegular getIsStrEmpty:orderModel.coalUnitName]) {
        
    }else{
        self.labCoalUnit.text = CJStringWithFormat(@"卸货数量(%@)",orderModel.coalUnitName);
    }
    
    [self.switchInRecive addTarget:self action:@selector(switchInSureAction:)forControlEvents:UIControlEventValueChanged | UIControlEventTouchDragExit];
    self.switchInRecive.transform = CGAffineTransformMakeScale(0.75, 0.75);
    self.switchInRecive.onTintColor = [UIColor cjMainColor];
    
    [self.switchabnormal addTarget:self action:@selector(switchAbnormalAction:)forControlEvents:UIControlEventValueChanged | UIControlEventTouchDragExit];
    self.switchabnormal.transform = CGAffineTransformMakeScale(0.75, 0.75);
    self.switchabnormal.onTintColor = [UIColor cjMainColor];
  
    [self.arrLoadimgs removeAllObjects];
    [self.arrUnloadimgs removeAllObjects];
    
//    self.arrLoadimgs = (NSMutableArray *)self.model.fillImageInfoList;
//    self.arrUnloadimgs = (NSMutableArray *)self.model.signImageInfoList;
    // 过滤空字符
    for (int i = 0; i < self.model.fillImageInfoList.count; i ++) {
        
        if ([CJControl getIsEmpty:self.model.fillImageInfoList[i]]) {
        }else{
            [self.arrLoadimgs addObject:self.model.fillImageInfoList[i]];
        }
    }
    
    for (int i = 0; i < self.model.signImageInfoList.count; i ++) {
        
        if ([CJControl getIsEmpty:self.model.signImageInfoList[i]]) {
        }else{
            [self.arrUnloadimgs addObject:self.model.signImageInfoList[i]];
        }
    }
    
    
    if (self.arrUnloadimgs.count == 0) {
        self.viewShowUnloadImg.hidden = YES;
    }else{
        self.viewShowUnloadImg.hidden = NO;
    }
    if (self.arrLoadimgs.count == 0) {
        self.viewShowLoadImg.hidden = YES;
    }else{
        self.viewShowLoadImg.hidden = NO;
    }
    
    for (int i = 0; i < self.arrLoadimgs.count; i++) {

        UIImageView* cell = [[UIImageView alloc]init];
        cell.userInteractionEnabled = YES;
        [cell enableFlexLayout:YES];

        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sellLoadImageCell:)];
        cell.tag = i + 3000;
        [cell addGestureRecognizer:tap];

        [cell setLayoutAttrStrings:@[
                                     @"width",@"75",
                                     @"height",@"75",
                                     @"margin",@"1%",
                                     @"alignItems",@"center",
                                     @"justifyContent",@"center",
                                     ]];
        [cell setViewAttr:@"bgColor" Value:@"#E4E9ED"];
        [cell setViewAttr:@"borderRadius" Value:@"0"];
        [_imgLoadImgParent insertSubview:cell atIndex:i];
        [_imgLoadImgParent markDirty];
    //    cell.layer.contents = (id) img.CGImage;
    //    UIImageView *imgV;
        [cell sd_setImageWithURL:[NSURL URLWithString:self.arrLoadimgs[i]] placeholderImage:[UIImage imageNamed:@"zcj_error_image"]];
    }
    
    for (int i = 0; i < self.arrUnloadimgs.count; i++) {

        UIImageView* cell = [[UIImageView alloc]init];
        cell.userInteractionEnabled = YES;
        [cell enableFlexLayout:YES];

        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sellUnloadImageCell:)];
        cell.tag = i + 4000;
        [cell addGestureRecognizer:tap];

        [cell setLayoutAttrStrings:@[
                                     @"width",@"75",
                                     @"height",@"75",
                                     @"margin",@"1%",
                                     @"alignItems",@"center",
                                     @"justifyContent",@"center",
                                     ]];
        [cell setViewAttr:@"bgColor" Value:@"#E4E9ED"];
        [cell setViewAttr:@"borderRadius" Value:@"0"];
        [_imgUnloadImgParent insertSubview:cell atIndex:i];
        [_imgUnloadImgParent markDirty];
    //    cell.layer.contents = (id) img.CGImage;
    //    UIImageView *imgV;
        [cell sd_setImageWithURL:[NSURL URLWithString:self.arrUnloadimgs[i]] placeholderImage:[UIImage imageNamed:@"zcj_error_image"]];
    }
    
    [header layoutIfNeeded];
    
    self.tableView.tableHeaderView = header;
    [self.tableView reloadData];
}

///查看装货照片
/// @param sender <#sender description#>
-(void)sellLoadImageCell:(UIGestureRecognizer*)sender{
    UIView* cell = sender.view;
    [[XLImageViewer shareInstanse] showNetImages:self.arrLoadimgs index:(int)cell.tag - 3000 fromImageContainer:cell];
}

///查看卸货照片
/// @param sender <#sender description#>
-(void)sellUnloadImageCell:(UIGestureRecognizer*)sender{
    UIView* cell = sender.view;
    [[XLImageViewer shareInstanse] showNetImages:self.arrUnloadimgs index:(int)cell.tag - 4000 fromImageContainer:cell];
}

-(void)switchInSureAction:(UISwitch *)sender{

    if([sender isOn]){
        self.strIsReceiptReturn = @"1";
        self.fieldReceiptNum.enabled = YES;
        self.touchViewReturn.userInteractionEnabled = YES;
    }else{
        self.strIsReceiptReturn = @"0";
        self.fieldReceiptNum.enabled = NO;
        self.touchViewReturn.userInteractionEnabled = NO;
    }

}

-(void)switchAbnormalAction:(UISwitch *)sender{

    if([sender isOn]){
        NSLog(@"turn on");
        self.strIsAbnormal = @"1";
        self.touchViewAbnormal.userInteractionEnabled = YES;
        self.fieldAbnormalFee.enabled = YES;
    }else{
        NSLog(@"turned off");
        self.strIsAbnormal = @"0";
        self.touchViewAbnormal.userInteractionEnabled = NO;
        self.fieldAbnormalFee.enabled = NO;
    }
}

#pragma mark ----------其他费用
- (void)btnAddOtherFeeAction{
//    [CJAlert showStringDismissWithDelay:@"其他费用"];
    WS(ws);
    AddOtherFeeVC *vc = [AddOtherFeeVC new];
//    NSMutableArray *arr = [[NSMutableArray alloc]init];
    vc.strCode = self.strCode;
    vc.arrList = self.arrOtherList;
    vc.blockSuccess = ^(NSString *str, NSMutableArray *list) {
        ws.strOrderExtraFeeList = [CJControl convertToJsonDataFromArray:(NSArray *)list];
        ws.arrOtherList = list;
        ws.fieldOtherFee.text = str;
    };
    [self pushVc:vc];
}

- (void)btnSureUnloadGoodsAction{
    
    __block NSString *strReturnImgs = @"";
    if (self.arrReturnOrder.count > 0) {
        [self.arrReturnOrder enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (idx == 0) {
                strReturnImgs = obj;
            }else{
                strReturnImgs = CJStringWithFormat(@"%@,%@",strReturnImgs,obj);
            }
        }];
    }
    
    __block NSString *strAbnormalImgs = @"";
    if (self.arrAbnormalOrder.count > 0) {
        [self.arrAbnormalOrder enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (idx == 0) {
                strAbnormalImgs = obj;
            }else{
                strAbnormalImgs = CJStringWithFormat(@"%@,%@",strAbnormalImgs,obj);
            }
        }];
    }
    
    // 回单
    if ([self.strIsReceiptReturn isEqualToString:@"1"]) {
        
        if ([self.fieldReceiptNum.text isEqualToString:@""]) {
            [CJAlert showStringDismissWithDelay:@"请填写回单号"];
            return;
        }
        
        if ([strReturnImgs isEqualToString:@""]) {
            [CJAlert showStringDismissWithDelay:@"请上传回单照片"];
            return;
        }
    }else{
        self.fieldReceiptNum.text = @"";
        strReturnImgs = @"";
    }
    // 异常
    if ([self.strIsAbnormal isEqualToString:@"1"]) {
        
        if ([self.fieldAbnormalFee.text isEqualToString:@""]) {
            [CJAlert showStringDismissWithDelay:@"请填写异常费用"];
            return;
        }
        if ([strAbnormalImgs isEqualToString:@""]) {
            [CJAlert showStringDismissWithDelay:@"请上传异常照片"];
            return;
        }
    }else{
        self.fieldAbnormalFee.text = @"";
        strAbnormalImgs = @"";
    }
    
    NSString *strURL = CJStringWithFormat(@"%@/ntocc-tms-api/orderDetail/orderDetailFinish",CJBaseUrl);
    NSDictionary *dicPar = @{@"code":self.strCode, //@"16f113c77b7a42a5a9b7d231fc9ad39e", //
                             @"isUnloadingConfirm":@"1",
                             @"receiptImgList":strReturnImgs, //回单照片
                             @"abnormalImgList":strAbnormalImgs,// 异常照片
                             @"orderExtraFeeList":self.strOrderExtraFeeList, //其他费用列表
                             @"isReceiptReturn":self.strIsReceiptReturn, //回单是否已收：0->未收取，1->已收取
                             @"receiptNum":self.fieldReceiptNum.text, //回单号    self.strIsAbnormal = @"1";
                             @"isAbnormal":self.strIsAbnormal, //是否异常：0->正常，1->异常
                             @"abnormalRemark":self.fieldAbnormalRemark.text,//异常原因
                             @"abnormalFee":self.fieldAbnormalFee.text, //扣除异常费用
                             @"extraFee":self.fieldOtherFee.text // 其他费用
                            };
    
    WS(ws);
    [[HDNetworking sharedHDNetworking] PUT:strURL parameters:dicPar success:^(id  _Nonnull responseObject) {
        
//        DLog(@"++++++++%@",responseObject);
        if (ws.blockSuccess) {
            ws.blockSuccess(@"");
        }
        [ws pop];
    } failure:^(NSError * _Nonnull error) {
        DLog(@"++++++++%@",error);
        
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 0.01;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *MeViewCellId = @"DriverAouthVCcellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MeViewCellId];
    if (cell ==nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MeViewCellId];
//        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return cell;
}

- (CJTableView *)tableView{
    if (!_tableView) {
        _tableView = CJTableView.tbInitFrameStyle(CGRectMake(0, kTopHeight + CJTableToTopHeight, SCREEN_WIDTH, SCREEN_HEIGHT-kTopHeight - CJTableToTopHeight),UITableViewStylePlain)
        .tbDelegate(self)
        .tbDataSource(self)
        .tbSetOther(YES)
        .tbEstimatedRowHeight(YES)
//        .tbMjHeadFooter(YES)
        ;
//        WS(ws);
//        _tableView.blockMjHeader = ^(BOOL isheader) {
//
//            if (isheader) {
//                [ws downRefresh];
//            } else {
//                [ws upRefresh];
//            }
//
//        };
    }
    
    return _tableView;
}

@end


